#pragma once
#include "cocos2d.h"
#include "GameConfig.h"
#include "EventHelper.h"
#include "UI.h"
#include "UICommon.h"
#include "UISettingComponent.h"

USING_NS_CC;
using namespace UISettingComponent;
class UISettingPanel;

class UISetting :public LayerColor, public EventHelper
{
	public:
	UISetting() :EventHelper(this) {};

	static UISetting* create(unsigned int eventflag = 1U);
	void close();
	void onTabClick();

	UISettingPanel* panel;

	private:
	int tabcount = 0;
	vector<UICButton*> tabs;

	void createTitle();
	void createTab(string name, string iconfile = "");
	void createPanel(float panelheight, int pagecount, int colcount, int rowcount);

	void onMouseDown(Event* e);
};

class UISettingPanel :public LayerGradient
{
	public:
	UISettingPanel() {};
	static UISettingPanel* create(float panelheight, int pagecount, int colcount, int rowcount);

	void addOption(int page, int col, int row, string name, Node* uicomponent);
	void createOptions();

	private:
	int pagecount, colcount, rowcount;
	float baseposx, panelheight, colwidth, rowheight;
	Size uicsize;
};

class UISettingKeybind :public LayerColor, public EventHelper
{
	public:
	UISettingKeybind() :EventHelper(this) {};
	static UISettingKeybind* create(
		Size size,
		int keycount,
		int gamestyle,
		Color4B bgcolor,
		Color4B fgcolor
	);

	Size size;
	Color4B fgcolor;
	Color4B bgcolor;
	int keyCount;
	KEYCODE* keySet;
	Label** keyLabels;

	private:
	void createKeyLabels(KEYCODE* keyset, int keycount);
	//void setKeyLabel(KEYCODE keycode);
	static string mapKeycodeToString(KEYCODE keycode);

	//void onMouseMove(Event* e);
	//void onMouseDown(Event* e);
};